extends Node

## 背包系统演示脚本
## 用于自动演示背包系统的各种功能

@onready var inventory_system: InventorySystem
var demo_timer: Timer
var demo_step: int = 0

func _ready():
	# 获取背包系统引用
	inventory_system = get_node("/root/Node2D/UI/InventorySystem")
	
	# 创建演示定时器
	demo_timer = Timer.new()
	demo_timer.wait_time = 2.0
	demo_timer.timeout.connect(_on_demo_timer_timeout)
	add_child(demo_timer)
	
	# 开始演示
	start_demo()

func start_demo():
	print("=== 背包系统功能演示开始 ===")
	demo_step = 0
	demo_timer.start()

func _on_demo_timer_timeout():
	match demo_step:
		0:
			print("步骤 1: 打开背包")
			inventory_system.show_inventory()
			
		1:
			print("步骤 2: 添加各种物品")
			for item in inventory_system.available_items:
				var count = 1 if not item.can_stack() else randi_range(1, 3)
				inventory_system.add_item(item, count)
				await get_tree().create_timer(0.5).timeout
			
		2:
			print("步骤 3: 演示物品堆叠")
			var potion = inventory_system.available_items[2]  # 生命药水
			inventory_system.add_item(potion, 5)
			
		3:
			print("步骤 4: 演示背包已满情况")
			for i in range(10):
				var random_item = inventory_system.available_items[randi() % inventory_system.available_items.size()]
				inventory_system.add_item(random_item, 1)
			
		4:
			print("步骤 5: 清空背包")
			for slot in inventory_system.inventory_slots:
				slot.clear_slot()
			inventory_system.inventory_changed.emit()
			
		5:
			print("步骤 6: 重新添加物品进行最终展示")
			for item in inventory_system.available_items:
				inventory_system.add_item(item, 1)
			
		6:
			print("=== 演示结束 ===")
			print("您现在可以手动测试以下功能:")
			print("- 按 I 键切换背包")
			print("- 拖拽物品进行移动")
			print("- 双击消耗品使用")
			print("- 点击左侧按钮添加物品")
			demo_timer.stop()
			return
	
	demo_step += 1

func demonstrate_drag_and_drop():
	"""演示拖拽功能（需要手动操作）"""
	print("请手动测试拖拽功能:")
	print("1. 拖拽物品到其他槽位")
	print("2. 拖拽相同物品进行堆叠")
	print("3. 拖拽不同物品进行交换")

func demonstrate_item_usage():
	"""演示物品使用功能"""
	print("请双击生命药水来使用它")
	print("使用后物品数量会减少")

func show_inventory_stats():
	"""显示背包统计信息"""
	print("=== 背包统计 ===")
	var total_items = 0
	var occupied_slots = 0
	
	for slot in inventory_system.inventory_slots:
		if not slot.is_empty():
			occupied_slots += 1
			total_items += slot.item_count
	
	print("已占用槽位: ", occupied_slots, "/", inventory_system.inventory_slots.size())
	print("物品总数: ", total_items)
	
	print("\n各物品数量:")
	for item in inventory_system.available_items:
		var count = inventory_system.get_item_count(item)
		if count > 0:
			print("- ", item.item_name, ": ", count)
